package com.flying.client;

import com.flying.client.network.IMsgHandler;
import com.flying.client.network.INetworkSink;
import com.flying.client.network.NetworkClient;
import com.flying.client.network.NetworkProvider;
import com.flying.client.network.NetworkResult;
import com.flying.client.network.msg.ORMsg;
import com.flying.client.ui.InitSessionHandler;
import com.flying.client.ui.MsgType;
import com.flying.client.utils.Logger;

import android.app.Application;


public class OuyuApplication extends Application {
	
	private static Logger logger = Logger.getLogger(OuyuApplication.class.getName());;
	
	@Override 
	public void onCreate()
	{
		logger.debug("onCreate");
//		NetworkProvider.init(new NetworkSink());
//		
//		NetworkProvider.getInstance().addServerInfo("192.168.0.123", 8054);
//		//NetworkProvider.getInstance().addServerInfo("192.168.0.123", 10102);
//		//NetworkProvider.getInstance().addServerInfo("192.168.0.123", 10103);
//		
//		NetworkProvider.getInstance().registerMsgHandler(MsgType.INIT, new InitSessionHandler());
//		NetworkProvider.getInstance().connect();
	}
	
	public class NetworkSink implements INetworkSink
	{
		@Override
		public void onConnected(NetworkResult result) {
			logger.debug("networkCallback onConnect result.isSuccess="+result.isSuccess());
			if (result.getClient() != null)
			{
				logger.debug("onConnect client["+result.getClient().serverIp()+":"+result.getClient().serverPort()+"]");
			}
		}

		@Override
		public void onClosed(NetworkResult result) {
			// TODO Auto-generated method stub
			logger.debug("networkCallback onClose result.isSuccess="+result.isSuccess());
			if (result.getClient() != null)
			{
				logger.debug("onClose client["+result.getClient().serverIp()+":"+result.getClient().serverPort()+"]");
			}
		}

		@Override
		public void onPaused(NetworkResult result) {
			// TODO Auto-generated method stub
			logger.debug("networkCallback onPause result.isSuccess="+result.isSuccess());
			if (result.getClient() != null)
			{
				logger.debug("onPause client["+result.getClient().serverIp()+":"+result.getClient().serverPort()+"]");
			}
		}

		@Override
		public void onDisConnectioned(NetworkResult result) {
			// TODO Auto-generated method stub
			logger.debug("networkCallback onDisConnection result.isSuccess="+result.isSuccess());
			if (result.getClient() != null)
			{
				logger.debug("onDisConnection client["+result.getClient().serverIp()+":"+result.getClient().serverPort()+"]");
			}
		}
		
		public void onError(Throwable throwable,NetworkClient client)
		{
			logger.debug("networkCallback onError e="+throwable);
			
			if (client != null)
			{
				logger.debug("onDisConnection client["+client.serverIp()+":"+client.serverPort()+"]");
			}
		}

		@Override
		public void onReceivedMsg(ORMsg msg) {
			logger.debug("networkcallback onReceive msg="+msg);
		}

		@Override
		public void registerMsgHandler(short msgType, IMsgHandler msgHandler) {
			
		}

		@Override
		public void unregisterMsgHandler(short msgid) {
			// TODO Auto-generated method stub
			
		}
	}
}
